<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
	<head>
	<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no"/> 
		<meta name="apple-mobile-web-app-capable" content="yes" /> 
		<title>Lifecycle and Controller Test</title> 
		<script type="text/javascript">
			dojoConfig = {
				parseOnLoad: false,
				async:1,
				app: {debugApp: 0}  // set debugApp to log app transitions and view activate/deactivate
			};
		</script>
		<script type="text/javascript" src="../../../../../dojo/dojo.js"></script>

		<script>
            // the actual  launcher
            require(["./modelApp.js"], function(){});
        </script>
		<script type="text/javascript">
			require([
				"doh/runner",
				"dojo/topic",
				"dojo/_base/lang",
				"dojox/mobile/TransitionEvent",				
				"dojo/parser",
				"dojo/when",
 				"dojox/app/controllers/Load", 
 				"dojox/app/controllers/Transition", 
 				"dojox/app/controllers/Layout",
  				"dojox/app/controllers/History",
  				"dojox/app/controllers/HistoryHash",
  				"dojox/app/utils/config", 
				"dojox/json/ref", 
				"dojo/sniff",
				"dojo/text!./config.json"  				
					], function(doh, topic, lang, TransitionEvent, parser, when, Load, Transition, Layout, History, HistoryHash,
						configUtil, jsonRef, has, config) {
						var originalConfig = jsonRef.fromJson(config);
						var isTablet = false;
						var width = window.innerWidth || document.documentElement.clientWidth;
						if(width > 600){
							isTablet = true;
						}

						has.add("testTrue", true);
						has.add("tablet", isTablet);
						has.add("phone", !isTablet);
						has.add("notIE", !has("ie"));
						
						// configUtil.configProcessHas is only called here to test the configProcessHas, normally the app does not call it directly
						config = configUtil.configProcessHas(originalConfig);
						doh.register("Test-HasConfig", [{
							name : "test-HasConfig",
							runTest : function(t) {
								var dfd = new doh.Deferred();
								setTimeout(function() {
									t.assertEqual(config.controllers[0], "dojox/app/controllers/Load");
									t.assertEqual(config.configTestSetTrueInHas, "SetInHasOk");
									t.assertEqual(config.configTestNotSetInHas, "InitOk");
									if(config.isTablet){
										t.assertEqual(config.configTestTablet, "Yes");
										t.assertEqual(config.configTestPhone, "No");
									}else{
										t.assertEqual(config.configTestTablet, "No");
										t.assertEqual(config.configTestPhone, "Yes");
									}
									return dfd.callback(true);
								}, 500);
								return dfd;
							}
						}, {
							// Test controllers
							name : "test-Controllers",
							runTest : function(t) {
								var dfd = new doh.Deferred();
								setTimeout(function() {
									// test controllers
									t.assertEqual(4, config.controllers.length);
									if(has("ie")){
										t.assertEqual(config.controllers[3], "dojox/app/controllers/HistoryHash");										
										t.assertTrue(testApp.controllers[3] instanceof HistoryHash);
									}else{
										t.assertEqual(config.controllers[3], "dojox/app/controllers/History");										
										t.assertTrue(testApp.controllers[3] instanceof History);
									}
									return dfd.callback(true);
								}, 500);
								return dfd;
							}
						}]);

						doh.run();
						

					});
		</script>
	</head>
	<body>
	</body>
</html>
